package com.gxgeek.redis.application.application.geodistance;

import com.gxgeek.redis.application.redistool.JedisExecutor;
import redis.clients.jedis.GeoCoordinate;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * redis 计算物理距离
 * @author gaoxing
 * @create 2017-09-27 上午11:08
 */
public class GeoRedis {



    //初始化 批量 放入 redis GEO
    public static void init(String key, List<GeoUser> userList){
        Map<String, GeoCoordinate> memberCoordinateMap = new HashMap<>();
        for (int i = 0 ;i<userList.size();i++){
            GeoUser user = userList.get(i);
            memberCoordinateMap.put(user.getId(),new GeoCoordinate(user.getLongitude(),user.getLatitude()));
        }
        JedisExecutor.executeNR(jedis -> jedis.geoadd(key, memberCoordinateMap));
    }
}
